package com.example.qa_back.utils;

import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

/**
 * @author 董帅
 * @date 2021/3/10 - 17:38
 */
public class UploadFile {
    public static String uploadVoice(MultipartFile file) {
        String originalName = file.getOriginalFilename();
        assert originalName != null;
        String suffixName = originalName.substring(originalName.lastIndexOf("."));
        String filePath = "F:/q_a/voice/";
//        String filePath = "/root/q_a/voice/";
        String newFileName = UUID.randomUUID() + suffixName;
        File dest = new File(filePath + newFileName);
        try {
            file.transferTo(dest);
            return filePath + newFileName;
        } catch (IOException e) {
            e.printStackTrace();
            return "error";
        }
    }
}
